const mongoose = require('mongoose')

mongoose.connect('mongodb://localhost:27017/local').then(res=>{
    console.log('dataBase connect success')

    let vSchema = new mongoose.Schema({
        firstName:{
            type:String,
            required:true
        },
        lastName:{
            type:String,
            required:true
        }
    })

    vSchema.virtual('fullName').get(function(){
        return this.firstName+' '+this.lastName;
    })

    vSchema.set('toJSON',{getters:true, virtual:true})

    let vModel = mongoose.model('vModel',vSchema)

    let v = new vModel({
        firstName:'triss',
        lastName:'abc'
    })

    console.log(v.fullName,'===fullName')
    console.log('json:',JSON.stringify(v))
    
})

